

package com.nhc.activity_fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.astrob.model.Msg;
import com.astrob.nhcmap.R;
import com.nhc.database.manager.DBDataCenter;

import zuo.biao.library.base.BaseTabActivity;
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.ui.AlertDialog;
import zuo.biao.library.ui.TopMenuWindow;

/**
 * 使用方法：复制>粘贴>改名>改代码
 */

/**
 * 带标签的Activity示例
 *
 * @use toActivity(DemoTabActivity.createIntent(...));
 */
public class MapSelectTabActivity extends BaseTabActivity implements OnClickListener, OnBottomDragListener, AlertDialog.OnDialogButtonClickListener {
    private final String TAG = "MapSelectTabActivity";

    /**
     * 启动这个Activity的Intent
     *
     * @param context
     * @return
     */
    public static Intent createIntent(Context context) {
        return new Intent(context, MapSelectTabActivity.class);
    }

    //启动方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    @Override
    public Activity getActivity() {
        return this;
    }

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, this);

        //功能归类分区方法，必须调用<<<<<<<<<<
        initView();
        initData();
        initEvent();
        //功能归类分区方法，必须调用>>>>>>>>>>

    }


    //UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    //示例代码<<<<<<<<
    //示例代码>>>>>>>>
    @Override
    public void initView() {//必须在onCreate方法内调用
        super.initView();

        //示例代码<<<<<<<<
        addTopRightButton(newTopRightImageView(context, R.drawable.btn_menu_selector)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                toActivity(TopMenuWindow.createIntent(context, getResources().getStringArray(R.array.top_menu_mapselecttab)), REQUEST_TO_TOP_MENU, false);
            }
        });
        //示例代码>>>>>>>>
    }


    //UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //Data数据区(存在数据获取或处理代码，但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    @Override
    public void initData() {//必须在onCreate方法内调用
        super.initData();
    }

    @Override
    @Nullable
    public String getTitleName() {
        return getString(R.string.mapselecttab_titlte);
    }

    @Override
    @Nullable
    public String getReturnName() {
        return "";
    }

    @Override
    @Nullable
    public String getForwardName() {
        return "";
    }

    @Override
    protected String[] getTabNames() {
        return getResources().getStringArray(R.array.top_bar_mapselecttab);
    }

    @Override
    protected Fragment getFragment(int position) {
        //示例代码<<<<<<<<<<<<<<<<<<
        Fragment fragment;
        switch (position) {
            default:
            case 0: {
                MapOnlineListFragment f = MapOnlineListFragment.createInstance();
                f.setFatherHandler(mHandler);
                fragment = f;
            }
            break;
            case 1: {
                MapofflineListFragment f = MapofflineListFragment.createInstance();
                f.setFatherHandler(mHandler);
                fragment = f;
            }
            break;
        }

        Bundle bundle = fragment.getArguments();
        if (bundle == null) {
            bundle = new Bundle();
        }
//        bundle.putInt(DemoListFragment.ARGUMENT_POSITION, position);
        fragment.setArguments(bundle);
        //示例代码>>>>>>>>>>>>>>>>>>
        return fragment;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case Msg.NAVITRACK_NAVI:
                    break;
            }
        }
    };

    //Data数据区(存在数据获取或处理代码，但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    @Override
    public void initEvent() {//必须在onCreate方法内调用
        super.initEvent();
        topTabView.setOnTabSelectedListener(this);//覆盖super.initEvent();内的相同代码
    }

    @Override
    public void onDragBottom(boolean rightToLeft) {
        //示例代码<<<<<<<<<<<<<<<<<<
        if (rightToLeft) {
            return;
        }

        finish();
        //示例代码>>>>>>>>>>>>>>>>>>
    }

    @Override
    public void onTabSelected(TextView tvTab, int position, int id) {
        super.onTabSelected(tvTab, position, id);
//        showShortToast("onTabSelected  position = " + position);
    }

    //类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch (keyCode) {
            default:
                break;
            case 21://left
                if (currentPosition == 1) {
                    topTabView.selectUI(0);
                    selectFragment(0);
                }
                break;
            case 22://right
                if (currentPosition == 0) {
                    topTabView.selectUI(1);
                    selectFragment(1);
                }
                break;
        }

        return super.onKeyUp(keyCode, event);
    }


    //类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    //系统自带监听方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    //系统自带监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    private final int REQUEST_TO_TOP_MENU = 30;

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case REQUEST_TO_TOP_MENU:
                if (data != null) {
                    switch (data.getIntExtra(TopMenuWindow.RESULT_POSITION, -1)) {
                        case 0:
                            onMapsetting();
                            break;
                        default:
                            break;
                    }
                }
                break;
        }
    }

    private void onMapsetting() {
        toActivity(MapSettingActivity.createIntent(context), 1);
    }

    @Override
    public void onDialogButtonClick(int requestCode, boolean isPositive) {
        if (isPositive == false) {
            return;
        }

        if (requestCode == 11) {

        }

    }

    //内部类,尽量少用<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


    //内部类,尽量少用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}